
// 深拷贝
function deepClone(target, map = new Map()) {
    if (map.has(target)) {
      return map.get(target)
    }
    const type = Object.prototype.toString.call(target)
    let clone
    if (type === '[object Object]') {
      clone = {};
      map.set(target, clone);
      for (let key in target) {
        if (target.hasOwnProperty(key)) {
          clone[key] = deepClone(target[key], map);
        }
      }
    } else if (type === '[object Array]') {
      clone = [];
      map.set(target, clone);
      target.forEach(item => {
        clone.push(deepClone(item, map));
      });
    }  else {
      clone = target
    }
    return clone
  }
  const target = {
    field1: 1,
    field2: undefined,
    field3: {
      child: 'child'
  
    },
    field4: [2, 3, 8],
  };
  target.target = target
  let cloneTarget = deepClone(target)
  target.field4.push(9)
  console.log(target, '---target');
  console.log(cloneTarget, '---new ');
  